import { request } from '../../utils/request.js'
Page({
    data: {
        checkedId: '', //选中地址项的ID
        show: false,
        addressList: [{
                id: 1,
                name: '阿巴阿巴',
                tel: '13208844541',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号'
            },
            {
                id: 2,
                name: '和单价',
                tel: '185454545545',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号',
                isdefault: true
            },
            {
                id: 3,
                name: '扣分啊',
                tel: '121245454545',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号'
            },
            {
                id: 4,
                name: '扣分啊',
                tel: '121245454545',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号'
            }, {
                id: 5,
                name: '扣分啊',
                tel: '121245454545',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号'
            }, {
                id: 6,
                name: '扣分啊',
                tel: '121245454545',
                a: '云南省',
                b: '昆明市',
                c: '五华区',
                d: '西城时代15号'
            }
        ]
    },
    radioChange(e) {
        this.setData({ checkedId: e.detail.value })
        wx.showToast({
            title: `当前选中地址ID：${e.detail.value}`,
            icon: 'none'
        })
    },
    settingDefault(e) {
        const { index } = e.target.dataset
        let addressList = this.data.addressList
        addressList.forEach(item => {
            item.isdefault = false
        })
        addressList[index].isdefault = true
        this.setData({ addressList })
        wx.showToast({
            title: '设置成功',
            icon: 'success'
        })
    },
    delAddress(e) {
        const { index } = e.target.dataset
        this.setData({ show: true, deleteIndex: index })
    },
    delete() {
        let addressList = this.data.addressList
        let index = this.data.deleteIndex
        addressList.splice(index, 1)
        this.setData({ addressList })
        wx.showToast({
            title: '删除成功',
            icon: 'success'
        })
    },
    onLoad: function(options) {
        // request({
        //     url: '/home/user/addr/detail',
        //     method: 'GET',
        //     success(data) {
        //         console.log(data)
        //     }
        // })
    }
})